package cn.b.training.baby_education_training.repository;

import cn.b.training.baby_education_training.entity.Encyclo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @program: baby_education
 * @description
 * @author: wuying
 * @create: 2022-11-29 10:26
 **/
@Repository
public interface EncycloRepository extends JpaRepository<Encyclo,Long> {
    /**
     * 通过id获取百科信息
     * @param id
     * @return
     */
    @Query("select a from Encyclo a where a.id=?1")
    Encyclo getByEncycloId(Long id);

    @Query("select a from Encyclo a where a.encycloTitle LIKE CONCAT('%',?1,'%') ")
    List<Encyclo> getEncycloByTitle(@Param("encycloTitle") String encycloTitle);

    /**
     * 通过科学id获取百科信息
     * @param scienceTagId
     * @return
     */
    @Query("select a from Encyclo a where a.scienceTagId=?1")
    List<Encyclo> getByScienceId(Long scienceTagId);

    /**
     * 通过食谱id获取百科信息
     * @param foodTagId
     * @return
     */
    @Query("select a from Encyclo a where a.foodTagId=?1")
    List<Encyclo> getByFoodId(Long foodTagId);
}
